<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of ajax
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Ajax extends MY_Controller {

    //put your code here


    function ajax() {
        parent :: __construct();
        //put your code here
    }
    
    function populate_review_car_version($model) {
        $model = intval($model);
        $sql = "Select * from version where model_id=$model and status=51 order by version ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_version" >
            <option value="" selected="selected">Version</option>
            <option value="" disabled="disabled"></option>
            <?php foreach ($result as $version): { ?>
                    <option value=<?= $version->id; ?> > <?= $version->version; ?></option>

                <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }
    
    function populate_review_cal_model($make, $div) {
        $make = intval($make);
        $sql = "Select * from model where make_id=$make and status=51 order by model ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_model" onChange="get_ReviewCarVersion(this.value,'<?= base_url(); ?>');">
            <option value="" selected="selected">Select Model</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $model): {
                    ?>
                    <option value=<?= $model->id; ?> > <?= $model->model; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }
    
    
    function populate_car_version($model) {
        $model = intval($model);
        $sql = "Select * from version where model_id=$model and status=51 order by version ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_version">
            <option value="" selected="selected">Version</option>
            <option value="" disabled="disabled"></option>
            <?php foreach ($result as $version): { ?>
                    <option value=<?= $version->id; ?> > <?= $version->version; ?></option>

                <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_cal_model($make, $div) {
        $make = intval($make);
        $sql = "Select * from model where make_id=$make and status=51 order by model ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="car_model" onChange="getCarVersion(this.value,'<?= base_url(); ?>');">
            <option value="" selected="selected">Select Model</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $model): {
                    ?>
                    <option value=<?= $model->id; ?> > <?= $model->model; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

//=========LOCATION ===========================================//

    function populate_state() {
        $countryID = $_GET['country'];
        $sql = "Select id,state from state where country_id=$countryID and status=51 order by state ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>

        <select name="state" style="width: 200px" onChange="getCity(this.value,'<?= base_url(); ?>');">
            <option value="" selected="selected">State</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $state): {
                    ?>
                    <option value=<?= $state->id; ?> > <?= $state->state; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

    function populate_city($stateID) {
        $stateID = intval($stateID);
        $sql = "Select id,city from city where state_id=$stateID and status=51 order by city ASC";
        $query = $this->db->query($sql);
        $result = $query->result();
        ?>
        <select name="city">
            <option value="" selected="selected">City</option>
            <option value="" disabled="disabled">----------------</option>
            <?php
            foreach ($result as $city): {
                    ?>
                    <option value=<?= $city->id; ?> > <?= $city->city; ?></option>
                    <?php
                }
            endforeach;
            ?>
        </select>
        <?php
    }

//-- Contact Seller Ajax Call ------Subha (08/09/2012)-----//
    function contact_seller($seller_id = 0) {
        $this->load->model('member_model');
        $data['member']['info'] = $this->member_model->get_member($seller_id);
        $data['title'] = "CONTACT SELLER";
        $this->template->set_layout('contact_form');
        $this->template->title('title')
                ->build('pages/contact_seller', $data);
        //print $data['member']['info']->email;
        //die();
    }

//-- Contact Buyer Ajax Call ------Subha (08/09/2012)-----//
    function contact_buyer($buyer_id = 0) {
        $this->load->model('member_model');
        $data['member']['info'] = $this->member_model->get_member($buyer_id);
        $data['title'] = "CONTACT BUYER";

        $this->template->set_layout('contact_form');
        $this->template->title('title')
                ->build('pages/contact_seller', $data);
        //print $data['member']['info']->email;
        //die();
    }
    function submit_contact_seller(){
       
        $name=$_POST['my_name'];
        $contact_no=$_POST['my_contact'];
        $email=$_POST['my_email'];
        $location=$_POST['my_location'];
        $description=$_POST['my_query'];
        $prefix='CS';
        $post_data=array('name'=>$name,
                        'prefix'=>$prefix,
                        'email'=>$email,
                        'contact_no'=>$contact_no,
                        'location'=>$location,
                        'description'=>$description
                        );
        
       $this->db->insert('contact_master',$post_data);
    }
}
?>
